<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Admin\Controller;

/**
 * Description of OrderController
 *
 * @author Administrator
 */
class OrderController extends BaseController{
    //put your code here
    /*
     * 预约信息列表
     */
    public function order_list(){
        $name = I('name');
        if($name){
            $where['name'] = $name;
            $did = M('doctor')->field('did')->where($where)->find();
            $map['o.did'] = $did['did'];
        }
        $mobile = I('mobile');
        if($mobile){
            $map['o.mobile'] = $mobile;
        }
        $order_time = I('order_time');
        if($order_time){
            $map['o.order_time'] = strtotime($order_time);
        }
        //保证查询时，分页页码从1开始
        if (IS_POST) {
            $_GET['p'] = 1;
        }
        $count = M('orders')->alias("o")->where($map)->count();
        $pagesize = 15;
        $Page = new \Think\Page($count, $pagesize);

        if (!empty($map)) {
            $param = empty($param) ? I('') : array_merge($param, I(''));
            //分页跳转的时候保证查询条件
            if (!empty($param)) {
                foreach ($param as $key => $val) {
                    $Page->parameter[$key] = urlencode($val);
                }
            }
        }
        $re = M('orders')->alias('o')->field('o.*,d.name as dname')->join('doctor as d on d.did = o.did')->limit($Page->firstRow,$Page->listRows)->where($map)->select();
        $this->assign('page',$Page->show());
        $this->assign('re',$re);
        $this->display();
    }
    /*
     * 预约确认
     */
    public function audit(){
        $where['oid'] = I('oid');
        $data['status'] = I('status');
        if($where['oid'] && $data['status']){
            $re = M('orders')->where($where)->save($data);
            $this->success("确认成功");
        }else{
            $this->error("信息不完整");
        }
    }
}
